package com.example.demo2.generator.service.impl;

import com.example.demo2.generator.entity.CarInsurance;
import com.example.demo2.generator.mapper.CarInsuranceDao;
import com.example.demo2.generator.service.CarInsuranceService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆保险(CarInsurance)表服务实现类
 *
 * @author makejava
 * @since 2024-09-20 09:41:28
 */
@Service("carInsuranceService")
public class CarInsuranceServiceImpl implements CarInsuranceService {
    @Resource
    private CarInsuranceDao carInsuranceDao;

    /**
     * 通过ID查询单条数据
     *
     * @param carInsId 主键
     * @return 实例对象
     */
    @Override
    public CarInsurance queryById(Integer carInsId) {
        return this.carInsuranceDao.queryById(carInsId);
    }

    /**
     * 分页查询
     *
     * @param carInsurance 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CarInsurance> queryByPage(CarInsurance carInsurance, PageRequest pageRequest) {
        long total = this.carInsuranceDao.count(carInsurance);
        return new PageImpl<>(this.carInsuranceDao.queryAllByLimit(carInsurance, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param carInsurance 实例对象
     * @return 实例对象
     */
    @Override
    public CarInsurance insert(CarInsurance carInsurance) {
        this.carInsuranceDao.insert(carInsurance);
        return carInsurance;
    }

    /**
     * 修改数据
     *
     * @param carInsurance 实例对象
     * @return 实例对象
     */
    @Override
    public CarInsurance update(CarInsurance carInsurance) {
        this.carInsuranceDao.update(carInsurance);
        return this.queryById(carInsurance.getCarInsId());
    }

    /**
     * 通过主键删除数据
     *
     * @param carInsId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer carInsId) {
        return this.carInsuranceDao.deleteById(carInsId) > 0;
    }

    @Override
    public List<CarInsurance> queryAllIns() {
        return carInsuranceDao.queryAllIns();
    }

    @Override
    public List<CarInsurance> queryAllByLike(CarInsurance carInsurance) {
        return carInsuranceDao.queryAllByLike(carInsurance);
    }

    @Override
    public int deleteBatch(List<CarInsurance> list) {
        return carInsuranceDao.deleteBatch(list);
    }
}
